package com.hangwei.aicabinet.util;

import android.content.Context;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.hangwei.aicabinet.App;
import com.hangwei.aicabinet.R;

/**
 * author: 张龙臣
 * date: 2018-08-28.
 */

public class ToastUtil {

    private static Toast mToast;
    private static Toast mToast0;

    public static void showCenterToast(String msg) {
        if (mToast == null)
            mToast = Toast.makeText(App.getInstance(), msg, Toast.LENGTH_SHORT);
        else mToast.setText(msg);
        mToast.setGravity(Gravity.CENTER, 0, 0);
//        int gravity = mToast.getGravity();
        mToast.show();
    }

    public static void showToast(String msg) {
        if (mToast0 == null)
            mToast0 = Toast.makeText(App.getInstance(), msg, Toast.LENGTH_SHORT);
        else mToast0.setText(msg);
        mToast0.show();
    }

    public static void showImgToast(Context context, String msg) {
        mToast = Toast.makeText(App.getInstance(), msg, Toast.LENGTH_SHORT);
        mToast.setGravity(Gravity.CENTER, 0, 0);
        LinearLayout toastView = (LinearLayout) mToast.getView();
        ImageView imageCodeProject = new ImageView(context);
        imageCodeProject.setImageResource(R.drawable.logo);
        toastView.addView(imageCodeProject, 0);
        mToast.show();
    }
}
